package com.tongji.housediy.view.skins.buttonskin
{
	import com.tongji.housediy.model.CompEnableStateModel;
	
	import flash.events.MouseEvent;
	
	import mx.binding.utils.BindingUtils;
	import mx.controls.Image;
	import mx.core.DragSource;
	import mx.managers.DragManager;
	
	import org.robotlegs.mvcs.Mediator;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class ViewPointBtnMediator extends Mediator
	{
		[Inject]
		public var view:ViewPointBtnSkin;
		
		[Inject]
		public var model:CompEnableStateModel;
		
		override public function onRegister():void
		{
			BindingUtils.bindProperty(view, "enabled", model, "isViewPointBtnEnable");
			
			view.hostComponent.addEventListener(MouseEvent.MOUSE_DOWN, viewPointBtnClickHandler);
		}
		
		private function viewPointBtnClickHandler(event:MouseEvent):void
		{
			var ds:DragSource = new DragSource();
			
			var btnImage:Image = new Image();
			btnImage.width = 27;
			btnImage.height = 27;
			btnImage.source = "assets/images/viewPoint.png";
			btnImage.x = view.mouseX;
			btnImage.y = view.mouseY;
			
			ds.addData("test", "characterFormat");
			
			DragManager.doDrag(view, ds, event, btnImage);
		}
	}
}